package flc.ast.activity;

import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.blankj.utilcode.util.ToastUtils;

import flc.ast.BaseAc;
import flc.ast.HomeActivity;
import flc.ast.R;
import flc.ast.databinding.ActivityChangePwdBinding;
import flc.ast.utils.Content;
import flc.ast.view.PasscodeView;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.SPUtil;

public class ChangePwdActivity extends BaseAc<ActivityChangePwdBinding> {


    @Override
    protected int onCreate() {
        return R.layout.activity_change_pwd;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);

        mDataBinding.ivChangePwdBack.setOnClickListener(v -> getOnBackPressedDispatcher().onBackPressed());

        mDataBinding.tvInputAnswerNext.setOnClickListener(this);

        mDataBinding.passcodeView.setListener(new PasscodeView.PasscodeViewListener() {
            @Override
            public void onFail() {
                mDataBinding.passcodeView.getWrongStatusColor();
            }

            @Override
            public void onSuccess(String number) {
                SPUtil.putString(mContext, Content.myPassword, number);
                ToastUtils.showShort(getString(R.string.change_pwd_suc));
                startActivity(HomeActivity.class);
            }
        });
    }

    @Override
    protected void onClickCallback(View v) {
        if (v.getId() == R.id.tvInputAnswerNext) {
            String answer = mDataBinding.etInputAnswerText.getText().toString().trim();
            if (answer.isEmpty()) return;
            String myAnswer = SPUtil.getString(mContext, Content.myAnswer, "");
            if (answer.equals(myAnswer)) {
                mDataBinding.llInputSecure.setVisibility(View.GONE);
                mDataBinding.llChangePwd.setVisibility(View.VISIBLE);
            } else {
                ToastUtils.showShort(getString(R.string.answer_is_error));
            }
        }
    }

    @Override
    protected void initData() {
        String problem = SPUtil.getString(mContext, Content.myProblem, "");
        mDataBinding.tvAnswerProblem.setText(problem);
    }
}